<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\common\model;

use think\Model;

class AdminGroup extends Model
{
    public function menus()
    {
        return $this->belongsToMany('AdminMenu','AdminGroupMenu','w_menu_id','w_group_id');
    }


    /**
     * 获取子孙树，将子孙作为父集数组的子集
     * @param array $data 待处理的数据集
     * @param int $id 要找的子节点id：查找所有为顶级分类id
     * @param int $lev 节点等级
     * @return array $sonTree 子孙树
     */
    public function getSubTreeb($data,$id=0){
        $sonTree =array();
        foreach ($data as $key=>$value){
            if($value['parent_id']==$id){
                $child=$this->getSubTreeb($data,$value['menu_id']);
                $value['child']=empty($child)?'':$child;
                $sonTree[$value['menu_id']]=$value;
            }
        }
        return $sonTree;
    }

}